package group2assignone.ucm.administrator;

import group2assignone.model.Manager;
import group2assignone.ucm.UCController;
import group2assignone.view.UITool;
import group2assignone.view.administrator.AdminMainView;
import group2assignone.view.administrator.EditManagerView;

/**
 * Use Case: Edit Manager                                                   <br>
 * Pre-condition: User has clicked edit from the  Admin Main view.          <br>
 * Post-condition: Edit Manager view is run                                 <br>
 * 1. system checks that a manager was selected<br>
 * 2. system closes the Admin Main view                                     <br>
 * 3. system retrieves the selected manager data                            <br>
 * 4. system runs the edit manager view                                     <br>
 *      1. a) No Manager was seleted<br>
 *              - Display error<br>
 * @author group2                                                           <br>
 */
public class UCEditManager implements UCController {

    // private Manager model;
    private AdminMainView view;
    private Manager man;

    public UCEditManager(AdminMainView a_View) {
        this.view = a_View;
        man = new Manager();
    }


    public void run() {
        //1. system checks that a manager was selected
        if (view.getSelectedRow() >= 0) {  //if have selection
            //2. system closes the Admin Main view
            view.dispose();
            System.out.println("in edit manager");
            System.out.println("selected row = " + view.getSelectedRow());

            //3. system retrieves the selected manager data
            String[] data = view.getRow();
            int index = 0;

            man.setUsername(data[index++]);
            man.setPassword(data[index++]);
            man.setFName(data[index++]);
            man.setLName(data[index++]);
            man.setDob(data[index]);

            //4. system runs the edit manager view
            EditManagerView mView = new EditManagerView(man);
            mView.go();
        } else {
            //1. a) No Manager was seleted
            //          - Display error
            UITool.displayError("Select a Manager to Edit!!!", view);
        }
    }
}








